// action must be string with 'expand' or 'collapse'
return;
}
- if ( typeof $defaultToggle !== 'undefined' && !($defaultToggle instanceof jQuery) ) {
- // is optional (may be undefined), but if passed it must be an instance of jQuery and nothing else
+ if ( typeof $defaultToggle == 'undefined' ) {
+ $defaultToggle = null;
+ }
+ if ( $defaultToggle !== null && !($defaultToggle instanceof jQuery) ) {
+ // is optional (may be undefined), but if defined it must be an instance of jQuery.
+ // If it's not, abort right away.
+ // After this $defaultToggle is either null or a valid jQuery instance.
return;
}
+
var $containers = null;
if ( action == 'collapse' ) {
// Slide doens't work with tables, but fade does as of jQuery 1.1.3
// http://stackoverflow.com/questions/467336#920480
$containers = $collapsible.find( '>tbody>tr' );
- if ( typeof $defaultToggle !== 'undefined' && ($defaultToggle instanceof jQuery) ) {
+ if ( $defaultToggle ) {
// Exclude tablerow containing togglelink
$containers.not( $defaultToggle.closest( 'tr' ) ).stop(true, true).fadeOut();
} else {
} else if ( $collapsible.is( 'ul' ) || $collapsible.is( 'ol' ) ) {
$containers = $collapsible.find( '> li' );
- if ( $defaultToggle && $defaultToggle.jquery ) {
+ if ( $defaultToggle ) {
// Exclude list-item containing togglelink
$containers.not( $defaultToggle.parent() ).stop( true, true ).slideUp();
} else {
// Expand the element
if ( $collapsible.is( 'table' ) ) {
$containers = $collapsible.find( '>tbody>tr' );
- if ( $defaultToggle && $defaultToggle.jquery ) {
+ if ( $defaultToggle ) {
// Exclude tablerow containing togglelink
$containers.not( $defaultToggle.parent().parent() ).stop(true, true).fadeIn();
} else {
} else if ( $collapsible.is( 'ul' ) || $collapsible.is( 'ol' ) ) {
$containers = $collapsible.find( '> li' );
- if ( $defaultToggle && $defaultToggle.jquery ) {
+ if ( $defaultToggle ) {
// Exclude list-item containing togglelink
$containers.not( $defaultToggle.parent() ).stop( true, true ).slideDown();
} else {
var $that = $(that),
$collapsible = $that.closest( '.mw-collapsible.mw-made-collapsible' ).toggleClass( 'mw-collapsed' );
e.preventDefault();
+ e.stopPropagation();
// It's expanded right now
if ( !$that.hasClass( 'mw-collapsible-toggle-collapsed' ) ) {
toggleLinkPremade = function( $that, e ) {
var $collapsible = $that.eq(0).closest( '.mw-collapsible.mw-made-collapsible' ).toggleClass( 'mw-collapsed' );
e.preventDefault();
+ e.stopPropagation();
// It's expanded right now
if ( !$that.hasClass( 'mw-collapsible-toggle-collapsed' ) ) {
// For the initial state call of customtogglers there is no event passed
if (e) {
e.preventDefault();
+ e.stopPropagation();
}
// Get current state and toggle to the opposite
var action = $collapsible.hasClass( 'mw-collapsed' ) ? 'expand' : 'collapse';
$collapsible.toggleClass( 'mw-collapsed' );
- toggleElement( $collapsible, action, $that )
+ toggleElement( $collapsible, action, $that );
};
// Initial state
if ( $that.hasClass( 'mw-collapsed' ) ) {
$that.removeClass( 'mw-collapsed' );
- toggleLinkCustom( $customTogglers, null, $that )
+ toggleLinkCustom( $customTogglers, null, $that );
}
// If this is not a custom case, do the default:
// If theres no toggle link, add it
if ( !$toggle.size() ) {
// Make sure the numeral order doesn't get messed up, reset to 1 unless value-attribute is already used
- // WebKit return '' if no value, Mozilla returns '-1' is no value
- if ( $firstItem.attr( 'value' ) == '' || $firstItem.attr( 'value' ) == '-1' ) { // Will fail with ===
+ // WebKit return '' if no value, Mozilla returns '-1' is no value.
+ // Needs ==, will fail with ===
+ if ( $firstItem.attr( 'value' ) == '' || $firstItem.attr( 'value' ) == '-1' ) {
$firstItem.attr( 'value', '1' );
}
$that.prepend( $toggleLink.wrap( '<li class="mw-collapsible-toggle-li"></li>' ).parent() );